<?php

	namespace app\Index\controller;
	use think\Controller;
	use think\Request;
	use think\Db;
	use think\Session;

	class Ranking extends Controller
	{
		public function ph()
		{
		    $host = "https://ali-qqmusic.showapi.com";
		    $path = "/top";
		    $method = "GET";
		    $appcode = "b7879a105ed74aa3ae2c7514f89e6374";
		    $headers = array();
		    array_push($headers, "Authorization:APPCODE " . $appcode);
		    $querys = "topid=5";
		    $bodys = "";
		    $url = $host . $path . "?" . $querys;

		    $curl = curl_init();
		    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
		    curl_setopt($curl, CURLOPT_URL, $url);
		    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
		    curl_setopt($curl, CURLOPT_FAILONERROR, false);
		    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		    curl_setopt($curl, CURLOPT_HEADER, false);
		    if (1 == strpos("$".$host, "https://"))
		    {
		        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
		        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
		    }
		    $file_contents=curl_exec($curl);
		    curl_close($curl);
		    $json = json_decode($file_contents,true);
		    $ph = $json['showapi_res_body']['pagebean']['songlist'];
		    // var_dump($ph);die;
		    return $ph;
			
		}



		public function ranking()
		{
			$this->assign('phone',Session::get('user.phone') );
			$ranking = $this->ph();
			// var_dump($ranking);
			return $this->fetch('ranking/ranking',[
					'ranking'=>$ranking
				]);
		}
	}

